package red.uec.service.impl;

import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import red.uec.entity.DataDictionary;
import red.uec.mapper.DataDictionaryMapper;
import red.uec.model.DataDictionaryModel;
import red.uec.model.DataDictionaryQueryRequest;
import red.uec.model.DataDictionaryQueryResponse;
import red.uec.service.DataDictionaryService;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 数据字典表 服务实现类
 * </p>
 *
 * @author 谭剑晖
 * @since 2018-11-13
 */
@Service
@Slf4j
@Transactional
public class DataDictionaryServiceImpl extends ServiceImpl<DataDictionaryMapper, DataDictionary> implements DataDictionaryService {
    public DataDictionaryQueryResponse query(DataDictionaryQueryRequest request){
        List<DataDictionary> dataDictionaryList =  this.selectList(Condition.create()
                .setSqlSelect("*")
                .eq("group_id", request.getGroupId()));

        List<DataDictionaryModel> dataDictionaryModelList = new ArrayList<>();
        for(DataDictionary dataDictionary : dataDictionaryList){
            DataDictionaryModel dataDictionaryModel = new DataDictionaryModel();
            dataDictionaryModel.setId(dataDictionary.getId());
            dataDictionaryModel.setName(dataDictionary.getName());
            dataDictionaryModelList.add(dataDictionaryModel);
        }
        return new DataDictionaryQueryResponse(dataDictionaryModelList).success();
    }
}
